//package misc;
//
///*******************************************************************************
// * Copyright (c) 2008, 2010 Xuggle Inc.  All rights reserved.
// *  
// * This file is part of Xuggle-Xuggler-Main.
// *
// * Xuggle-Xuggler-Main is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Lesser General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * Xuggle-Xuggler-Main is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Lesser General Public License for more details.
// *
// * You should have received a copy of the GNU Lesser General Public License
// * along with Xuggle-Xuggler-Main.  If not, see <http://www.gnu.org/licenses/>.
// *******************************************************************************/
//
//import gui.DrawImage;
//import ij.ImagePlus;
//import ij.process.ImageProcessor;
//import java.awt.Color;
//import java.awt.Graphics2D;
//import java.awt.Point;
//import java.awt.Polygon;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.geom.Area;
//import java.awt.image.BufferedImage;
//import java.util.ArrayList;
//import java.util.LinkedList;
//import javax.media.Buffer;
//import javax.media.format.VideoFormat;
//import javax.media.util.ImageToBuffer;
//import javax.swing.JButton;
//import javax.swing.Timer;
//
//import camera.AbstractCamera;
//import trackingAlgorithms.Tracker;
//import trackingAlgorithms.blob.Blob;
//import algos.Isovist;
//
///**
// * Takes a media container, finds the first video stream,
// * decodes that stream, and then displays the video frames,
// * at the frame-rate specified by the container, on a 
// * window.
// * @author aclarke
// *
// */
//public class CameraPlayerTest2 implements ActionListener
//{
//	private int timerDelay = 200;
//	private boolean start = true;
//	private Tracker tracker;
//    private ArrayList<Blob> blobs;
//    private DrawImage frame;
//	private Timer timer ;
//    private Isovist[]iso;
//    private LinkedList<Area> obstacles;
//    
//    /////////*Test Variables*/////////////
//  /**/  private final int NUMBER_OF_ELEMENTS = 1;          /**/
//  /**/  Point[] examples = new Point[NUMBER_OF_ELEMENTS];  /**/
//  /**/  private JButton up = new JButton("UP");            /**/
//  /**/  private JButton down = new JButton("Down");        /**/
//  /**/  private JButton left = new JButton("LEFT");        /**/
//  /**/  private JButton right = new JButton("RIGHT");      /**/
//  /**/	public BufferedImage background;                   /**/
//	///////////////////////////////////////////////////////
//    
//	public CameraPlayerTest2(){
//		tracker = new Tracker(1,null,null);
//		blobs = new ArrayList<Blob>();
//		timer = new Timer(timerDelay, this);
//		obstacles = new LinkedList<Area>();
//		Polygon ar = new Polygon(new int[]{60,10, 29, 6, 6 ,313,303,241}, new int[]{3,101,129,162,235,235,111,2}, 8);
//		Area area = new Area(ar);
////		Rectangle wall = new Rectangle(27, 65 , 45, 66); // create an obstacle
////		Area w = new Area(wall);
////		obstacles.add(w);
////		Rectangle wall2 = new Rectangle(20, 70 , 70, 10);
////		Area w2 = new Area(wall2);
////		obstacles.add(w2);
//		examples[0] = new Point(140,50);
//		for (int i = 0; i < obstacles.size(); i++) {
//			area.subtract(obstacles.get(i));
//		}
//		iso = new Isovist[tracker.cameras.size()]; 
//		for (int i = 0; i < tracker.cameras.size(); i++) {  //create visiblity polygon for each camera
//			iso[i] = new Isovist(area);
//		}
//		
//		tracker.setIsovist(iso);
//		
//		up.addActionListener(this);
//		down.addActionListener(this);
//		right.addActionListener(this);
//		left.addActionListener(this);
//		frame = new DrawImage(640,480);		
//		frame.add(up);
//		frame.add(down);
//		frame.add(left);
//		frame.add(right);
//		frame.setVisible(true);
//		timer.start();
//	}
//	
//	
//	public void run(){
//			
//		tracker.addImage(background, 0);	
//		tracker.createBackGround();
//		try {
//			Thread.sleep(10000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
//	public void start(BufferedImage javaImage){
//		if(javaImage!=null)
//			grabFrameImage(javaImage);
//	}
//
//
//	 public void grabFrameImage(BufferedImage b){
//		 frame.setFocusable(true);
//		 Buffer buf = ImageToBuffer.createBuffer(b, 30);
//		 VideoFormat vf = (VideoFormat) buf.getFormat();
//		 if(start){
//			  ImageProcessor imp = new ImagePlus("", b).getProcessor();
//			  for (int i = -5; i < 5; i++) {
//				for (int j = -5; j < 5; j++) {
//					for (int j2 = 0; j2 < examples.length; j2++) {
//						try{
//						imp.set(i+examples[j2].x, j+examples[j2].y, 0);
//						}catch(Exception e){}
//					}
//				}
//			}
//		  
//			  b = imp.getBufferedImage();
//			  tracker.processFrame(b, vf);
//			  blobs = tracker.getBlobs();
//			  Graphics2D g2 = b.createGraphics();
//			  Graphics2D backg2 = tracker.backGround.createGraphics();
//			  backg2.setColor(Color.red);
//			  for(Blob blob : blobs){
//				  g2.setColor(Color.red);
//				  int x = (int)blob.predectedX-blob.bounds.width/2;
//				  int y = (int)(vf.getSize().height- blob.predectedY)-blob.bounds.height/2 ;
//				  int width = blob.bounds.width;
//				  int height = blob.bounds.height;
//				  g2.drawRect(x, y, width, height);
//				  g2.setColor(Color.blue);
//				  g2.drawLine((int)blob.predectedX-5,(int)(vf.getSize().height- blob.predectedY),(int) blob.predectedX+5,(int)(vf.getSize().height- blob.predectedY));
//				  g2.drawString(blob.frameLabel+"", x+blob.bounds.width/2, y+blob.bounds.height/2);
//			  }
//			  for (int i = 0 ; i < iso.length;i++) {
//				  Point cam = new Point((int)tracker.cameras.get(i).getLocation().x, (int)tracker.cameras.get(i).getLocation().z);
//				  iso[i].doIso(cam);
////				  int index = 0;
////				  g2.drawPolygon(iso[index].polygon.xpoints,iso[index].polygon.ypoints,iso[index].polygon.npoints);
//			  }
//			  for (int i = 0; i < obstacles.size(); i++) {
//				g2.draw(obstacles.get(i));
//			}			  
//			  for (int i = 0; i < tracker.tUpdator.from.size(); i++) {
//				  Point from = new Point((int)tracker.tUpdator.from.get(i).x, (int)tracker.tUpdator.from.get(i).z);
//				  Point to = new Point((int)tracker.tUpdator.to.get(i).x, (int)tracker.tUpdator.to.get(i).z);			  
//				  g2.setColor(Color.BLUE);
//				  g2.drawLine(from.x, from.y, to.x, to.y);
//				  g2.setColor(Color.yellow);
//				  for(AbstractCamera camera : tracker.cameras)
//					  g2.drawLine((int)camera.getLocation().x,(int) camera.getLocation().z, (int)camera.getDirection().x, (int)camera.getDirection().z);
//			}
//			  frame.draw(b);
//	}
//	}
//
//  /**
//   * Forces the swing thread to terminate; I'm sure there is a right
//   * way to do this in swing, but this works too.
//   */
//  private static void closeJavaWindow()
//  {
//    System.exit(0);
//  }
//
//
//  @Override
//	public void actionPerformed(ActionEvent e) {
//		// TODO Auto-generated method stub
//			if(e.getSource() == timer){
//					start(background);
//			}
//			if(e.getSource()==up){
//				int sign = 1;
//				for (int i = 0; i< examples.length; i++) {
//					examples[i].y+=5*sign;
//					sign = -sign;
//				}
//			}
//			if(e.getSource()==down){
//				int sign = -1;
//				for (int i = 0; i< examples.length; i++) {
//					examples[i].y+=5*sign;
//					sign = -sign;
//				}
//			}
//			if(e.getSource()==right){
//				int sign = +1;
//				for (int i = 0; i< examples.length; i++) {
//					examples[i].x+=5*sign;
//					sign = -sign;
//				}
//			}
//			if(e.getSource()==left){
//				int sign = -1;
//				for (int i = 0; i< examples.length; i++) {
//					examples[i].x+=5*sign;
//					sign = -sign;
//				}
//			}
//  }	
//  
//  public static void main(String[] args) {
//	  CameraPlayerTest2 cam = new CameraPlayerTest2();
//	  cam.background = new ImagePlus("video_1.jpg").getBufferedImage();
//	  cam.run();
//}
//}